<script setup>
	
import {
		ref,
		onMounted
	} from 'vue'
	import {
		onShow,
		onReachBottom
	} from '@dcloudio/uni-app'
	
	const db = uniCloud.database();
	const dbCmd = db.command;
	const loadModal = ref(true)
	const movieList = ref([])
	onMounted(() => {
	    fetchAllData();
	})
	const fetchAllData = async () => {
	    try {
	        await Promise.all([getNews()]);
	        loadModal.value = false;
	    } catch (error) {
	        console.error("Error fetching data:", error);
	        // 处理错误，例如显示错误消息
	    }
	}
	const getNews = async () => {
	    const dataResult = await db.collection('movies')
	        .orderBy('movieId', 'desc')
	        .where({typeDesc:'综艺',cat:'大陆综艺',year:2024})
	        .skip(0)
	        .limit(12)
	        .get()
	    // 将最新电影数据插入到数组的第一个位置
	    movieList.value.unshift({title:'最新综艺', list:dataResult.result.data});
	}
	const goDetail = (id) => {
		uni.navigateTo({
			url: '/pages/playPage/playPage?id=' + id
		})
	}
</script>
<template>
	<view class="">
		<view class="cu-load load-modal" v-if="loadModal">
			<view class="cuIcon-search text-drab"></view>
			<view class="gray-text">加载中...</view>
		</view>
		<view class="bg-white" v-else v-for="item in movieList" :key="item.title">
			<view class="cu-bar">
				<view class="action">
					<text class="cuIcon-titles text-drab"></text>
					<text class="text-xl text-bold">{{item.title}}</text>
				</view>
			</view>
			<view class="grid col-3">
				<view v-for="item2 in item.list" :key="item._id" class="padding-xs" @tap="goDetail(item2.movieId)">
					<image :src="item2.image_thumb" style="height:320rpx;"></image>
					<view class="text-cut">{{item2.nm}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<style lang="scss">
</style>